package com.adingxiong.itemservice.controller;

import com.adingxiong.pojo.Item;
import com.adingxiong.service.ItemService;
import com.adingxiong.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName ItemController
 * @Description TODO
 * @Author xiongchao
 * @Date 2020/7/30 14:35
 **/

@RestController
@Slf4j
public class ItemController {

    @Autowired
    private ItemService itemService;

    @Value("${server.port}")
    private int port;


    @GetMapping("/getItems")
    public JsonResult<List<Item>> getItems(String order){
        log.info("server.port ={},orderId = {}",port,order);
        return JsonResult.ok().data(itemService.getItems(order)).msg("port:" + port);
    }

    @PostMapping("/decreaseNumber")
    public JsonResult decreaseNumber(@RequestBody List<Item> items) {
        itemService.decreaseNumbers(items);
        return JsonResult.ok();
    }
}
